var designClass = "design_class", hideClass = "hide_class", browseClass = "browse_class", addClass = "add_class", editClass = "edit_class";

var upWindow = window.parent.frames["zwIframe"];
if (!upWindow) {
    try {
        upWindow = window.parent.frames["componentDiv"].frames["zwIframe"];
    } catch (e) {
    }
    if (!upWindow) {
        upWindow = window.parent.frames["main"].frames["zwIframe"];
    }
}
//关闭自定义扩张控件弹出窗口
function fy_dialog_close() {
    window.parent.$(".layui-layer-iframe").parent().find(".layui-layer-close")
            .trigger("click");
}
function getUpFieldsByFieldval(name) {
    return upWindow.$("[fieldval*='displayName:\"" + name + "\"']");
}

function getUpFieldValue(field) {
    var fieldVal = field.attr("fieldVal");
    var editTag = field.hasClass(editClass);
    var browseTag = field.hasClass(browseClass);
    var addTag = field.hasClass(addClass);
    
    if (fieldVal != null && typeof (fieldVal) != 'undefined') {
        fieldVal = eval("(" + fieldVal + ")");
    } else {
        return null;
    }
    
    var obj = new Object();
    obj.displayName = fieldVal.displayName;
    obj.name = fieldVal.name;
    var tag = true;
    switch (fieldVal.inputType) {
        case "text":
        case "textarea":
            if (editTag) {
                obj.value = field.find("#" + fieldVal.name).val();
            } else if (browseTag) {
                obj.value = fieldVal.value;
            } else if (addTag) {
                obj.value = field.find("#" + fieldVal.name).val();
            }
            break;
        default:
            tag = false;
    }
    if (obj.value != undefined) {
        obj.value = obj.value.replace("\r\n", ";");
        obj.value = obj.value.replace("\n", ";");
    }
    return obj;
}
//设置值
function setUpFieldValue2(field, value, displayValue, index) {
    var fieldVal = field.attr("fieldVal");
    var editTag = field.hasClass(editClass);
    var browseTag = field.hasClass(browseClass);
    var addTag = field.hasClass(addClass);
    
    if (fieldVal != null && typeof (fieldVal) != 'undefined') {
        fieldVal = eval("(" + fieldVal + ")");
    } else {
        return null;
    }
    
    var tag = true;
    switch (fieldVal.inputType) {
        case "text":
        case "textarea":
            if (editTag) {
                field.find("#" + fieldVal.name).val(value);
                field.find("#" + fieldVal.name).trigger("blur");
            } else if (addTag) {
                field.find("#" + fieldVal.name).val(
                        field.find("#" + fieldVal.name).val() + value);
                field.find("#" + fieldVal.name).trigger("blur");
            }
            break;
        case "date":
            if (editTag) {
                field.find("#" + fieldVal.name).val(value);
                field.find("#" + fieldVal.name).trigger("blur");
            }
            break;
    }
}

var idnums = [];
var xmlObj = null; // 定义XMLHttpRequest对象
var idNumInputArray = getUpFieldsByFieldval("身份证");
var nameInputArray = getUpFieldsByFieldval("姓名");
var sexInputArray = getUpFieldsByFieldval("性别");
var ageInputArray = getUpFieldsByFieldval("年龄");
var hometownNumInputArray = getUpFieldsByFieldval("户籍");
var shoolnameInputArray = getUpFieldsByFieldval("毕业学校");
var workyearInputArray = getUpFieldsByFieldval("工龄");
var diplomaInputArray = getUpFieldsByFieldval("学历");
var currentcompanyInputArray = getUpFieldsByFieldval("当前公司");
var expectedSalaryInputArray = getUpFieldsByFieldval("期望待遇");
var majorInputArray = getUpFieldsByFieldval("专业");
var currentPositionInputArray = getUpFieldsByFieldval("当前岗位");
var workPlaceInputArray = getUpFieldsByFieldval("工作地");
var RecruitmentChannelsInputArray = getUpFieldsByFieldval("招聘渠道");
var BasicInputArray = getUpFieldsByFieldval("基本月薪");
var MonthlyBonusInputArray = getUpFieldsByFieldval("月度奖金");
var MealAllowanceInputArray = getUpFieldsByFieldval("餐费补贴");
var TransportationSubsidyInputArray = getUpFieldsByFieldval("交通补贴");
var HousingSubsidiesInputArray = getUpFieldsByFieldval("电话补贴");
var CellPhoneSubsidyInputArray = getUpFieldsByFieldval("住房补贴");
var YearEndBonusInputArray = getUpFieldsByFieldval("年终奖");
var OtherSubsidiesInputArray = getUpFieldsByFieldval("月_其他收入");
var ComprehensiveMonthlyIncomeInputArray = getUpFieldsByFieldval("综合月收入");
var AnnualCashIncomeInputArray = getUpFieldsByFieldval("年度现金收入");
var WelfareInputArray = getUpFieldsByFieldval("福利");
var OtherBenefitsInputArray = getUpFieldsByFieldval("年_其他收入");
var ApplyIdtArray = getUpFieldsByFieldval("applyid");
var ApperanceArray= getUpFieldsByFieldval("人事部评分1");
var CharacterArray= getUpFieldsByFieldval("人事部评分2");
var KnowledgeArray= getUpFieldsByFieldval("人事部评分3");
var ResponsibilityArray= getUpFieldsByFieldval("人事部评分4");
var AttitudeArray= getUpFieldsByFieldval("人事部评分5");
var CommunicationCollaborationArray= getUpFieldsByFieldval("人事部评分6");
var FlexibilityArray= getUpFieldsByFieldval("人事部评分7");
var PressureCapacityArray= getUpFieldsByFieldval("人事部评分8");
var SelfRecognitionArray= getUpFieldsByFieldval("人事部评分9");
var LogicalThinkingArray= getUpFieldsByFieldval("人事部评分10");
var WorkExperienceArray= getUpFieldsByFieldval("人事部评分11");
var ProfessionalExpertiseArray= getUpFieldsByFieldval("人事部评分12");
var ProfessionalQualificationsArray= getUpFieldsByFieldval("人事部评分13");
var ProfessionalExperienceArray= getUpFieldsByFieldval("人事部评分14");
var ProfessionalSkillsArray= getUpFieldsByFieldval("人事部评分15");
var DevelopmentPotentialArray= getUpFieldsByFieldval("人事部评分16");
var AdvantageThanInternalCandidatesArray= getUpFieldsByFieldval("人事部评分17");
var LSSCArray= getUpFieldsByFieldval("人事部评分18");
var AOPOArray= getUpFieldsByFieldval("人事部评分19");
var EvelopingTalentsArray= getUpFieldsByFieldval("人事部评分20");
var AdvantageArray= getUpFieldsByFieldval("人事部填写_优势");
var DisadvantageArray= getUpFieldsByFieldval("人事部填写_劣势");
var ComprehensiveAssessmentArray= getUpFieldsByFieldval("人事部填写_综合评价");

var ApperanceArray2= getUpFieldsByFieldval("用人部门评分1");
var CharacterArray2= getUpFieldsByFieldval("用人部门评分2");
var KnowledgeArray2= getUpFieldsByFieldval("用人部门评分3");
var ResponsibilityArray2= getUpFieldsByFieldval("用人部门评分4");
var AttitudeArray2= getUpFieldsByFieldval("用人部门评分5");
var CommunicationCollaborationArray2= getUpFieldsByFieldval("用人部门评分6");
var FlexibilityArray2= getUpFieldsByFieldval("用人部门评分7");
var PressureCapacityArray2= getUpFieldsByFieldval("用人部门评分8");
var SelfRecognitionArray2= getUpFieldsByFieldval("用人部门评分9");
var LogicalThinkingArray2= getUpFieldsByFieldval("用人部门评分10");
var WorkExperienceArray2= getUpFieldsByFieldval("用人部门评分11");
var ProfessionalExpertiseArray2= getUpFieldsByFieldval("用人部门评分12");
var ProfessionalQualificationsArray2= getUpFieldsByFieldval("用人部门评分13");
var ProfessionalExperienceArray2= getUpFieldsByFieldval("用人部门评分14");
var ProfessionalSkillsArray2= getUpFieldsByFieldval("用人部门评分15");
var DevelopmentPotentialArray2= getUpFieldsByFieldval("用人部门评分16");
var AdvantageThanInternalCandidatesArray2= getUpFieldsByFieldval("用人部门评分17");
var LSSCArray2= getUpFieldsByFieldval("用人部门评分18");
var AOPOArray2= getUpFieldsByFieldval("用人部门评分19");
var EvelopingTalentsArray2= getUpFieldsByFieldval("用人部门评分20");
var AdvantageArray2= getUpFieldsByFieldval("用人部门填写_优势");
var DisadvantageArray2= getUpFieldsByFieldval("用人部门填写_劣势");
var ComprehensiveAssessmentArray2= getUpFieldsByFieldval("用人部门填写_综合评价");


function init() {
    for (var i = 0, length =  idNumInputArray.length; i < length; i++) {
    	 idnums.push(getUpFieldValue(idNumInputArray.eq(i)).value);
        setUpFieldValue2(nameInputArray.eq(i), "");
        setUpFieldValue2(sexInputArray.eq(i), "");
        setUpFieldValue2(ageInputArray.eq(i), "");
        setUpFieldValue2(hometownNumInputArray.eq(i), "");
        setUpFieldValue2(shoolnameInputArray.eq(i), "");
        setUpFieldValue2(workyearInputArray.eq(i), "");
        setUpFieldValue2(nameInputArray.eq(i), "");
        setUpFieldValue2(sexInputArray.eq(i), "");
        setUpFieldValue2(ageInputArray.eq(i), "");
        setUpFieldValue2(hometownNumInputArray.eq(i), "");
        setUpFieldValue2(shoolnameInputArray.eq(i), "");
        setUpFieldValue2(workyearInputArray.eq(i), "");
        setUpFieldValue2(diplomaInputArray.eq(i), "");
        setUpFieldValue2(currentcompanyInputArray.eq(i), "");
        setUpFieldValue2(expectedSalaryInputArray.eq(i), "");
        setUpFieldValue2(currentPositionInputArray.eq(i),"");
        setUpFieldValue2(RecruitmentChannelsInputArray.eq(i), "");
        setUpFieldValue2(workPlaceInputArray.eq(i), "");
        setUpFieldValue2(majorInputArray.eq(i),"");
        setUpFieldValue2(BasicInputArray.eq(i), "");
        setUpFieldValue2(MonthlyBonusInputArray.eq(i), "");
        setUpFieldValue2(MealAllowanceInputArray.eq(i), "");
        setUpFieldValue2(TransportationSubsidyInputArray.eq(i), "");
        setUpFieldValue2(HousingSubsidiesInputArray.eq(i),"");
        setUpFieldValue2(CellPhoneSubsidyInputArray.eq(i),"");
        setUpFieldValue2(YearEndBonusInputArray.eq(i),"");
        setUpFieldValue2(OtherSubsidiesInputArray.eq(i), "");
        setUpFieldValue2(ComprehensiveMonthlyIncomeInputArray.eq(i),"");
        setUpFieldValue2(AnnualCashIncomeInputArray.eq(i), "");
        setUpFieldValue2(WelfareInputArray.eq(i), "");
        setUpFieldValue2(OtherBenefitsInputArray.eq(i), "");
        setUpFieldValue2(ApplyIdtArray.eq(i), "");
      
        setUpFieldValue2(ApperanceArray.eq(i), "");
        setUpFieldValue2(CharacterArray.eq(i), "");
        setUpFieldValue2(KnowledgeArray.eq(i), "");
        setUpFieldValue2(ResponsibilityArray.eq(i), "");
        setUpFieldValue2(AttitudeArray.eq(i), "");
        setUpFieldValue2(CommunicationCollaborationArray.eq(i), "");
        setUpFieldValue2(FlexibilityArray.eq(i), "");
        setUpFieldValue2(PressureCapacityArray.eq(i), "");
        setUpFieldValue2(SelfRecognitionArray.eq(i), "");
        setUpFieldValue2(LogicalThinkingArray.eq(i), "");
        setUpFieldValue2(WorkExperienceArray.eq(i), "");
        setUpFieldValue2(ProfessionalExpertiseArray.eq(i), "");
        setUpFieldValue2(ProfessionalQualificationsArray.eq(i), "");
        setUpFieldValue2(ProfessionalExperienceArray.eq(i), "");
        setUpFieldValue2(ProfessionalSkillsArray.eq(i), "");
        setUpFieldValue2(DevelopmentPotentialArray.eq(i), "");
        setUpFieldValue2(AdvantageThanInternalCandidatesArray.eq(i), "");
        setUpFieldValue2(LSSCArray.eq(i), "");
        setUpFieldValue2(AOPOArray.eq(i), "");
        setUpFieldValue2(EvelopingTalentsArray.eq(i), "");
        setUpFieldValue2(AdvantageArray.eq(i), "");
        setUpFieldValue2(DisadvantageArray.eq(i), "");
        setUpFieldValue2(ComprehensiveAssessmentArray.eq(i), "");

        setUpFieldValue2(ApperanceArray2.eq(i), "");
        setUpFieldValue2(CharacterArray2.eq(i), "");
        setUpFieldValue2(KnowledgeArray2.eq(i), "");
        setUpFieldValue2(ResponsibilityArray2.eq(i), "");
        setUpFieldValue2(AttitudeArray2.eq(i), "");
        setUpFieldValue2(CommunicationCollaborationArray2.eq(i), "");
        setUpFieldValue2(FlexibilityArray2.eq(i), "");
        setUpFieldValue2(PressureCapacityArray2.eq(i), "");
        setUpFieldValue2(SelfRecognitionArray2.eq(i), "");
        setUpFieldValue2(LogicalThinkingArray2.eq(i), "");
        setUpFieldValue2(WorkExperienceArray2.eq(i), "");
        setUpFieldValue2(ProfessionalExpertiseArray2.eq(i), "");
        setUpFieldValue2(ProfessionalQualificationsArray2.eq(i), "");
        setUpFieldValue2(ProfessionalExperienceArray2.eq(i), "");
        setUpFieldValue2(ProfessionalSkillsArray2.eq(i), "");
        setUpFieldValue2(DevelopmentPotentialArray2.eq(i), "");
        setUpFieldValue2(AdvantageThanInternalCandidatesArray2.eq(i), "");
        setUpFieldValue2(LSSCArray2.eq(i), "");
        setUpFieldValue2(AOPOArray2.eq(i), "");
        setUpFieldValue2(EvelopingTalentsArray2.eq(i), "");
        setUpFieldValue2(AdvantageArray2.eq(i), "");
        setUpFieldValue2(DisadvantageArray2.eq(i), "");
        setUpFieldValue2(ComprehensiveAssessmentArray2.eq(i), "");
    }
    
}


function load() {
    if (window.XMLHttpRequest) {// 如果当前浏览器支持XMLHttpRequest则创建XMLHttpRequest对象
        xmlObj = new XMLHttpRequest();
    } else {
        if (window.ActiveXObject) {// 如果当前浏览器支持ActiveXObject则创建ActiveXObject对象
            xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
        } else {
            return;
        }
    }
    xmlObj.onreadystatechange = handleResponse;// 判断URL调用的状态值并处理
	  xmlObj.open("get",
            "./oa2hrController.do?method=idnumFindPersonInfo&idnums="
            +idnums, true);
    xmlObj.send();

}


//用于处理状态的函数
function handleResponse() {
	   if (xmlObj.readyState == 4){
		  //var success = false;
		   var success =true;
  //  alert(xmlObj.responseText);
        if (xmlObj.status == 200) {
            var datas = eval("[" + xmlObj.responseText + "]");
            if (datas.length == 1) {
                var personMap = datas[0];
            for (var i = 0, length =  idNumInputArray.length; i < length; i++) {
            var person = personMap["idnum"+ getUpFieldValue( idNumInputArray.eq(i)).value];
            setUpFieldValue2(nameInputArray.eq(i),
                                person["name"]);
                        setUpFieldValue2(sexInputArray.eq(i),
                                person["gender"]);
                        setUpFieldValue2(ageInputArray.eq(i),
                                person["age"]);
                        setUpFieldValue2(hometownNumInputArray.eq(i),
                                person["hometown"]);
                        setUpFieldValue2(shoolnameInputArray.eq(i),
                                person["shoolName"]);
                        setUpFieldValue2(workyearInputArray.eq(i),
                                person["workYear"]);
                        setUpFieldValue2(diplomaInputArray.eq(i),
                                person["cliploma"]);
                        setUpFieldValue2(currentcompanyInputArray.eq(i),
                                person["currentCompany"]);
                        setUpFieldValue2(expectedSalaryInputArray.eq(i),
                                person["expectedSalary"]);
                        setUpFieldValue2(currentPositionInputArray.eq(i),
                                person["currentPosition"]);
                        setUpFieldValue2(RecruitmentChannelsInputArray.eq(i),
                                person["RecruitmentChannels"]);
                        setUpFieldValue2(workPlaceInputArray.eq(i),
                                person["workPlace"]);
                        setUpFieldValue2(majorInputArray.eq(i),
                                person["major"]);
                        setUpFieldValue2(BasicInputArray.eq(i),
                                person["Basic"]);
                        setUpFieldValue2(MonthlyBonusInputArray.eq(i),
                                person["MonthlyBonus"]);
                        setUpFieldValue2(MealAllowanceInputArray.eq(i),
                                person["MealAllowance"]);
                        setUpFieldValue2(TransportationSubsidyInputArray.eq(i),
                                person["TransportationSubsidy"]);
                        setUpFieldValue2(HousingSubsidiesInputArray.eq(i),
                                person["HousingSubsidies"]);
                        setUpFieldValue2(CellPhoneSubsidyInputArray.eq(i),
                                person["CellPhoneSubsidy"]);
                        setUpFieldValue2(YearEndBonusInputArray.eq(i),
                                person["YearEndBonus"]);
                        setUpFieldValue2(OtherSubsidiesInputArray.eq(i),
                                person["OtherSubsidies"]);
                        setUpFieldValue2(ComprehensiveMonthlyIncomeInputArray.eq(i),
                                person["ComprehensiveMonthlyIncome"]);
                        setUpFieldValue2(AnnualCashIncomeInputArray.eq(i),
                                person["AnnualCashIncome"]);
                        setUpFieldValue2(WelfareInputArray.eq(i),
                                person["Welfare"]);
                        setUpFieldValue2(OtherBenefitsInputArray.eq(i),
                                person["OtherBenefits"]);
                        setUpFieldValue2(ApplyIdtArray.eq(i),
                                person["applyid"]);
           
                        setUpFieldValue2(ApperanceArray.eq(i),
                        		person["Apperance"]);
                        setUpFieldValue2(CharacterArray.eq(i),
                                person["Character"]);
                        setUpFieldValue2(KnowledgeArray.eq(i),
                                person["Knowledge"]);
                        setUpFieldValue2(ResponsibilityArray.eq(i),
                                person["Responsibility"]);
                        setUpFieldValue2(AttitudeArray.eq(i),
                                person["Attitude"]);
                        setUpFieldValue2(CommunicationCollaborationArray.eq(i),
                                person["CommunicationCollaboration"]);
                        setUpFieldValue2(FlexibilityArray.eq(i),
                                person["Flexibility"]);
                        setUpFieldValue2(PressureCapacityArray.eq(i),
                                person["PressureCapacity"]);
                        setUpFieldValue2(SelfRecognitionArray.eq(i),
                                person["SelfRecognition"]);
                        setUpFieldValue2(LogicalThinkingArray.eq(i),
                                person["LogicalThinking"]);
                        setUpFieldValue2(WorkExperienceArray.eq(i),
                                person["WorkExperience"]);
                        setUpFieldValue2(ProfessionalExpertiseArray.eq(i),
                                person["ProfessionalExpertise"]);
                        setUpFieldValue2(ProfessionalQualificationsArray.eq(i),
                                person["ProfessionalQualifications"]);
                        setUpFieldValue2(ProfessionalExperienceArray.eq(i),
                                person["ProfessionalExperience"]);
                        setUpFieldValue2(ProfessionalSkillsArray.eq(i),
                                person["ProfessionalSkills"]);
                        setUpFieldValue2(DevelopmentPotentialArray.eq(i),
                                person["DevelopmentPotential"]);
                        setUpFieldValue2(AdvantageThanInternalCandidatesArray.eq(i),
                                person["AdvantageThanInternalCandidates"]);
                        setUpFieldValue2(LSSCArray.eq(i),
                                person["LSSC"]);
                        setUpFieldValue2(AOPOArray.eq(i),
                                person["AOPO"]);
                        setUpFieldValue2(EvelopingTalentsArray.eq(i),
                                person["EvelopingTalents"]);
                        setUpFieldValue2(AdvantageArray.eq(i),
                                person["Advantage"]);
                        setUpFieldValue2(DisadvantageArray.eq(i),
                                person["Disadvantage"]);
                        setUpFieldValue2(ComprehensiveAssessmentArray.eq(i),
                                person["ComprehensiveAssessment"]);
                  
                
                        setUpFieldValue2(ApperanceArray2.eq(i),
                        		person["Apperance2"]);
                        setUpFieldValue2(CharacterArray2.eq(i),
                                person["Character2"]);
                        setUpFieldValue2(KnowledgeArray2.eq(i),
                                person["Knowledge2"]);
                        setUpFieldValue2(ResponsibilityArray2.eq(i),
                                person["Responsibility2"]);
                        setUpFieldValue2(AttitudeArray2.eq(i),
                                person["Attitude2"]);
                        setUpFieldValue2(CommunicationCollaborationArray2.eq(i),
                                person["CommunicationCollaboration2"]);
                        setUpFieldValue2(FlexibilityArray2.eq(i),
                                person["Flexibility2"]);
                        setUpFieldValue2(PressureCapacityArray2.eq(i),
                                person["PressureCapacity2"]);
                        setUpFieldValue2(SelfRecognitionArray2.eq(i),
                                person["SelfRecognition2"]);
                        setUpFieldValue2(LogicalThinkingArray2.eq(i),
                                person["LogicalThinking2"]);
                        setUpFieldValue2(WorkExperienceArray2.eq(i),
                                person["WorkExperience2"]);
                        setUpFieldValue2(ProfessionalExpertiseArray2.eq(i),
                                person["ProfessionalExpertise2"]);
                        setUpFieldValue2(ProfessionalQualificationsArray2.eq(i),
                                person["ProfessionalQualifications2"]);
                        setUpFieldValue2(ProfessionalExperienceArray2.eq(i),
                                person["ProfessionalExperience2"]);
                        setUpFieldValue2(ProfessionalSkillsArray2.eq(i),
                                person["ProfessionalSkills2"]);
                        setUpFieldValue2(DevelopmentPotentialArray2.eq(i),
                                person["DevelopmentPotential2"]);
                        setUpFieldValue2(AdvantageThanInternalCandidatesArray2.eq(i),
                                person["AdvantageThanInternalCandidates2"]);
                        setUpFieldValue2(LSSCArray2.eq(i),
                                person["LSSC2"]);
                        setUpFieldValue2(AOPOArray2.eq(i),
                                person["AOPO2"]);
                        setUpFieldValue2(EvelopingTalentsArray2.eq(i),
                                person["EvelopingTalents2"]);
                        setUpFieldValue2(AdvantageArray2.eq(i),
                                person["Advantage2"]);
                        setUpFieldValue2(DisadvantageArray2.eq(i),
                                person["Disadvantage2"]);
                        setUpFieldValue2(ComprehensiveAssessmentArray2.eq(i),
                                person["ComprehensiveAssessment2"]);
                success = true;
                
            }
     
       }
        }
      
        if (!success) {
            alert("请检查输入的身份证号");
      }  
        fy_dialog_close();
        }
	
	  
}
init();
load();
